<?php
class Product extends AppModel {
	var $name = 'Product';
	var $belongsTo = array(
			'Category' => array('className' => 'Category',
								'foreignKey' => 'category_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			),
			'Brand' => array(	'className' => 'Brand',
								'foreignKey' => 'brand_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			)
	);

	
	function findOrderList($condition = null) {
		// array to build list categories
		$return = array ( );
		// find all categories order by root_path
		$this->Category->recursive = 0;		
		$categories = $this->Category->findAll ($condition, null, 'Category.root_path' );
		foreach ( $categories as $category ) {
			$temp = "";
			$spaceAlowLevel = str_repeat('-', $category['Category']['level']-1);
			$temp .= $spaceAlowLevel.$category ['Category'] ['name'];				
			$return [$category ['Category'] ['id']] = $temp;
		}
		return $return;
	}
	function findBrandByOrderList($condition = null) {
		// array to build list categories
		$return = array ( );
		// find all categories order by root_path
		$this->Brand->recursive = 0;		
		$brands = $this->Brand->findAll($condition, null, 'orders' );
		foreach ( $brands as $brand ) {
			$temp = "";
			$spaceAlowLevel = str_repeat('- ', 0);
			$temp .= $spaceAlowLevel.$brand ['Brand'] ['name'];				
			$return [$brand ['Brand'] ['id']] = $temp;
		}
		return $return;
	}
}
?>